package com.hisense.hiioc.hismartplate.entity.table.typehandler;

import com.hisense.hiioc.hismartplate.entity.table.enumdefine.ScreenType;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: almo
 * @Date: 2019/1/3 下午1:35
 * @Version 1.0
 */
public class ScreenTypeHandler implements TypeHandler<ScreenType> {

    @Override
    public void setParameter(PreparedStatement ps, int i, ScreenType parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.getIndex());
    }

    @Override
    public ScreenType getResult(ResultSet rs, String columnName) throws SQLException {
        return ScreenType.valueOf(columnName);
    }

    @Override
    public ScreenType getResult(ResultSet rs, int columnIndex) throws SQLException {
        return ScreenType.intOf(columnIndex);
    }

    @Override
    public ScreenType getResult(CallableStatement cs, int columnIndex) throws SQLException {
        return ScreenType.intOf(columnIndex);
    }
}
